package com.xunwulian.dubbo.service.impl;

import com.xunwulian.api.dto.BaseResponse;
import com.xunwulian.api.iface.UserAPI;
import com.xunwulian.base.dao.UserDao;
import com.xunwulian.base.entity.Page;
import com.xunwulian.base.entity.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;

import java.util.List;

/**
 * Created by liyankai on 2017/3/13.
 */
@Service
public class UserApiImpl implements UserAPI {

    @Autowired
    private UserDao userDao;

    public UserApiImpl() {
    }

    @Override
    public BaseResponse<List<User>> listPage(Page page,
                                             String userNameKey,
                                             String appId,
                                             String userId) {

        List<User> list = userDao.listPage(page, appId, userId, userNameKey);

        BaseResponse response = new BaseResponse();
        response.setData(list);
        response.setPage(page);

        return response;
    }

    @Override
    public List<User> listAll() {
        return userDao.listAll();
    }

    @Override
    public User getByUid(String userId) {
        return userDao.getByUid(userId);
    }

    @Override
    public Integer countByRoleId(@Param("roleId") String roleId) {

        return userDao.countByRoleId(roleId);
    }

    @Override
    public User getByNameAndEmail(String email, String userName) {
        return userDao.getByNameAndEmail(email, userName);
    }

    @Override
    public User getByNameAndNumber(String number, String userName) {
        return userDao.getByNameAndNumber(number, userName);
    }

    @Override
    public User getByName(String userName) {
        return userDao.getByName(userName);
    }

    @Override
    public void editU(User user) {
        userDao.editU(user);
    }

    @Override
    public void saveU(User user) {
        userDao.saveU(user);
    }

    @Override
    public void deleteU(String userId) {
        userDao.deleteU(userId);
    }

    @Override
    public void deleteAllU(List<String> idList) {
        userDao.deleteAllU(idList);
    }

    @Override
    public void updateLastLogin(String lastLogin, String userId) {
        userDao.updateLastLogin(lastLogin, userId);
    }

    @Override
    public void saveIP(String ip, String userName) {
        userDao.saveIP(ip, userName);
    }

    @Override
    public User getUserByNameAndPwd(String userName, String password) {
        return userDao.getUserByNameAndPwd(userName, password);
    }

    @Override
    public void increaseBalance(String userId, Double balance) {
        userDao.increaseBalance(userId, balance);
    }

}
